package com.gst.cloudygovernance.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gst.cloudygovernance.R;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by YBH on 2017/12/18.
 */

public class RunFragmentAdapter extends BaseAdapter {
    private Context mContext;
    private Map<String, String> map = new HashMap<>();

    public RunFragmentAdapter(Context mContext) {
        this.mContext = mContext;
        initList();
    }

    private void initList() {
        for (int i = 0; i < 50; i++) {
            map.put("name"+i, "广州乌山垃圾处理场" + i + "号");
//            map.put("number1"+i, "站场数：" + i + "个");
//            map.put("number2"+i, "报警总数：" + i + "次");
//            map.put("number3"+i, "投产：" + i + "天");
        }
    }

    @Override
    public int getCount() {
        return map == null ? 0 : map.size();
    }

    @Override
    public Object getItem(int position) {
        return map.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_yxqk, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String s = map.get(position);
        //绑定数据
        holder.tvName.setText(map.get("name"+position));
//        holder.tvStationNum.setText(map.get("number1"+position));
//        holder.tvAlarmNum.setText(map.get("number2"+position));
//        holder.tvOperationNum.setText(map.get("number3"+position));
//        LogUtil.e("数组大小："+map.size());
        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.iv_icon)
        ImageView ivIcon;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_station_num)
        TextView tvStationNum;
        @Bind(R.id.tv_alarm_num)
        TextView tvAlarmNum;
        @Bind(R.id.tv_operation_num)
        TextView tvOperationNum;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
